# coding:utf-8

from PSOFT.vendor.Qt_py.Qt import QtCore, QtGui, QtWidgets

class pNumEdit(QtWidgets.QLineEdit):
    """description of class"""

    update = QtCore.Signal(str)

    def __init__(self, *args):
        super(pNumEdit, self).__init__(*args)
        self.__buff = ''
        self.targerkeys = []

        self.validator = QtGui.QDoubleValidator(0, 1, 3)
        self.setValidator(self.validator)

    def focusInEvent(self, e):
        super(pNumEdit, self).focusInEvent(e)
        self.__buff = self.text()

    def focusOutEvent(self, e):
        super(pNumEdit, self).focusOutEvent(e)
        if self.__buff != self.text():
            self.update.emit(self.text())

    def keyPressEvent(self, e):
        super(pNumEdit, self).keyPressEvent(e)
        if not self.targerkeys or e.key() in self.targerkeys:
            self.update.emit(self.text())
